﻿//                       NOTICE
// 
// This software was produced for the U. S. Government
// under Contract No. FA8721-10-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)
// 
// � 2010 The MITRE Corporation. All Rights Reserved. 

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Surface.Core;

namespace MXSE.MultiTouch.Gestures
{
    public abstract class BasicGesture : Gesture
    {
        //A ComplexGesture can have multiple BasicGesture children,
        //this is use to refer back the the parent.  Null if BasicGesture
        //has no parent.
        public virtual ComplexGesture Parent
        {
            get;
            set;
        }

        // Couple basic variables
        public DateTime startTime;
        public DateTime endTime;
        public Vector2 startPosition;
        public Vector2 lastPosition;
        public Vector2 currentPosition;
        public int Id;

        //Called to set the EndTime of a BasicGesture.
        public virtual void End()
        {
            endTime = DateTime.Now;
        }

        /// <summary>
        /// Calls base.Update() to perform necessary Actions,
        /// then updates the lastPosition variable to the currentPosition.
        /// </summary>
        public override void Update()
        {
            base.Update();
            lastPosition = currentPosition;
        }

        /// <summary>
        /// Called by ContactManager.ContactChanged(ContactEventArgs cea) to
        /// update the current position of the gesture.  Does not change the
        /// lastPosition at all, as that's done in the Update loop.
        /// </summary>
        /// <param name="cea"></param>
        public virtual void UpdateCurrentPosition(ContactEventArgs cea)
        {
            currentPosition.X = cea.Contact.X;
            currentPosition.Y = cea.Contact.Y;
        }

        /// <summary>
        /// Used to determine if the Gesture should be removed
        /// from the lists.  May be overridden by derived classes.
        /// </summary>
        /// <returns>True if gesture should be removed.</returns>
        public override bool Destroyed()
        {
            if (destroyed || endTime.CompareTo(DateTime.MinValue) != 0)
                return true;
            return false;
        }

    }
}
